<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>定位相关控件</title>
  <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js"></script>
  <script type="text/javascript" src="https://lib.baomitu.com/vue/2.6.12/vue.min.js"></script>
</head>
<body>
<div id="app">
  <h1>定位程序</h1>
  <p id="demo" type="text" v-model="port">{{port}}</p>
</div>

<script src="http://api.map.baidu.com/api?v=2.0&ak=7G4cl6wvFF5CnbHYUQLI6bqCnIdwZMlN"></script>

<script>
  var v = new Vue({
    el:'#app',
    data: {port:''}
  })
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition((r) => {
//定位结果对象会传递给r变量
  var point='';
  point=r.address.city;
  document.getElementById("demo").innerHTML=point;
  console.log(r)
  console.log(r.address.city);
  v.port=r.address.city;
});
//   var geolocation = new BMap.Geolocation();
//   geolocation.getCurrentPosition((r) => {
//     //定位结果对象会传递给r变量
//     console.log(r)
//   });

</script>
</body>
</html>